package com.thinkit.bigdata.web.service.impl.config;

import com.thinkit.bigdata.core.feature.orm.mybatis.Page;
import com.thinkit.bigdata.web.dao.config.SysStatusAttMapper;
import com.thinkit.bigdata.web.dao.config.SysStatusConfigMapper;
import com.thinkit.bigdata.web.model.config.SysStatusAttExample;
import com.thinkit.bigdata.web.model.config.SysStatusConfig;
import com.thinkit.bigdata.web.model.config.SysStatusConfigExample;
import com.thinkit.bigdata.web.service.config.StatusConfigService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by lihongli on 2018/8/30
 */
@Service
public class StatusConfigServiceImpl implements StatusConfigService {

    @Resource
    private SysStatusConfigMapper mapper;

    @Resource
    private SysStatusAttMapper statusAttMapper;

    @Override
    public List<SysStatusConfig> selectByExample(SysStatusConfigExample example){
        return mapper.selectByExample(example);
    }

    @Override
    public List<SysStatusConfig> selectByExample(Page<SysStatusConfig> page, SysStatusConfigExample example) {
        return mapper.selectByExample(page, example);
    }

    @Override
    public int countByExample(SysStatusConfigExample example) {
        return mapper.countByExample(example);
    }

    @Override
    public int insert(SysStatusConfig record) {
        return mapper.insertSelective(record);
    }

    @Override
    public SysStatusConfig statusConfigGetByPK(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public int update(SysStatusConfig record) {
        return mapper.updateByPrimaryKey(record);
    }

    @Override
    public int delete(SysStatusConfig record) {
        // 先删除属性状态表
        int rowNum = mapper.deleteByPrimaryKey(record.getId());
        // 再删除属性状态字段表关联内容
        SysStatusAttExample example = new SysStatusAttExample();
        example.createCriteria().andTypeEqualTo(record.getType());
        statusAttMapper.deleteByExample(example);
        return rowNum;
    }
}
